
function setup(wsurl, show_id) {
    url = "ws://" + window.location.hostname + ":" + window.location.port + wsurl;
    ws = new WebSocket(url);

    ws.onopen = function(e) {
        log("Connected\r\n", show_id);
        sendMessage("Connected")
    }

    ws.onclose = function(e) {
        log("Disconnected: " + e.reason, show_id);
    }

    ws.onerror = function(e) {
       log("Error ", show_id);
    }

    ws.onmessage = function(e) {
        const data = JSON.parse(e.data);
        // console.log(data);

        log(data.message, show_id);
    }
}

function sendMessage(msg, show_id){
    ws.send(msg);
    log("Message sent", show_id);
}

function log(s, show_id) {
    $(show_id).append(s);
}